home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD ROM Paradise Collection 4
/
CD ROM Paradise Collection 4 1995 Nov.iso
/
graphics
/
mm_tease.zip
/
SOURCE.LZH
/
VGA4PAGE.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1992-12-12
|
3KB
|
111 lines
Unit VGA4Page;
interface
Procedure Screen(page:byte);
Procedure SetMode13x4;
Procedure PutPixel(x,y:integer;color,page:byte);
Function GetPixel(x,y:integer;page:byte):byte;
Procedure HLine(x1,x2,y:integer;color,page:byte);
Procedure ClearScreen (page:byte);
Procedure CopyPage(page1,page2:byte);
implementation
const
StartIndex=0;
EndIndex=StartIndex+3;
Offset_Adr:Array[StartIndex..EndIndex] OF WORD=($0000,$3E80,$7D00,$BB80);
Segment_Adr:ARRAY[StartIndex..EndIndex] OF WORD=($A000,$A3E8,$A7D0,$ABB8);
Procedure Screen(page:byte);
begin
while (port[$3da] and 8)<>8 do;
while (port[$3da] and 8)=8 do;
port[$3D4]:=$0D;
port[$3D5]:=lo(offset_adr[page]);
port[$3D4]:=$0C;
port[$3D5]:=hi(offset_adr[page]);
end;
Procedure SetMode13x4;
begin
inline($b8/$13/$00/$cd/$10); { mov ax,0013h / int 10h }
port[$3C4]:=4;
port[$3C5]:=port[$3C5] AND $F7 OR $04;
port[$3C4]:=2;
port[$3C5]:=$0F;
fillchar(mem[$A000:$0000],$FFFF,0);
port[$3D4]:=$14;
port[$3D5]:=port[$3D5] AND $BF;
port[$3D4]:=$17;
port[$3D5]:=port[$3D5] OR $40;
screen(0);
end;
Procedure PutPixel(x,y:integer;color,page:byte);
begin
if (x<0) or (x>319) or (y<0) or (y>199) then
exit;
portw[$3C4]:=$0002 or ((1 shl (x and 3)) shl 8);
mem[segment_adr[page]:$50*y+x shr 2]:=color;
end;
Function GetPixel(x,y:integer; page:byte):byte;
begin
portw[$3CE]:=$0004 OR ((x mod 4) shl 8);
GetPixel:=mem[Segment_Adr[page]:x shr 2 + y*$50];
end;
Procedure HLine(x1,x2,y:integer;color,page:byte);
var
mask1,mask2:byte;
offset1,offset2:word;
begin
if (y<0) or (y>199) then exit;
if x1<0 then x1:=0;
if x1>319 then x1:=319;
if x2<0 then x2:=0;
if x2>319 then x2:=319;
mask1:=($F shl (x1 and 3));
mask2:=not ($FF shl ((x2 and 3)+1));
offset1:=x1 shr 2+y*$50;
offset2:=x2 shr 2+y*$50;
if offset1=offset2 then
mask1:=mask1 AND mask2
else
begin
portw[$3c4]:=$0002 or (mask2 shl 8);
mem[segment_adr[page]:offset2]:=color;
if offset2-offset1>1 then
begin
portw[$3C4]:=$0F02;
fillchar(mem[segment_adr[page]:offset1+1],offset2-offset1-1,color);
end;
end;
portw[$3c4]:=$0002 or (mask1 shl 8);
mem[segment_adr[page]:offset1]:=color;
end;
Procedure ClearScreen (page:byte);
begin
while (port[$3DA] and 8)<>8 do;
port[$3C4]:=2;
port[$3C5]:=$0F;
fillchar(mem[segment_adr[page]:$0000],$50*200,0);
end;
Procedure CopyPage(page1,page2:byte);
var
oldport:byte;
begin
port[$3CE]:=5;
oldport:=port[$3Cf];
port[$3CE]:=5;
port[$3CF]:=oldport and $FC or 1;
move(mem[segment_adr[page1]:0],mem[segment_adr[page2]:0],$50*200);
port[$3CE]:=5;
port[$3CF]:=oldport;
end;
end.